package com.wiloon.java8x.basic.math;


import com.alibaba.fastjson.JSON;

import java.math.BigDecimal;

/*
 * Created by roy on 6/28/17;
 */
public class MathX {
    public static void main(String[] args) {
        BigDecimal decimal = new BigDecimal(421000l);
        System.out.println(decimal.intValue());
    }


    public static void test0() {
        System.out.println(7 / 2);
        System.out.println(7 / 2.0);
        System.out.println(7 % 2);
    }

    public static void test() {
        BigDecimal decimal = new BigDecimal(1);
        System.out.println(decimal.toString());
        System.out.println(decimal.toPlainString());

        int i = 2;
        System.out.println();

        BigDecimal decimal1 = new BigDecimal(1.123456789);
        System.out.println(decimal1);

        System.out.println(decimal1.setScale(5, BigDecimal.ROUND_UP));

        System.out.println(new BigDecimal("1.065800000000000000027929047963226594220031984150409698486328125").setScale(4, BigDecimal.ROUND_UP));
        System.out.println(new BigDecimal("1.06580000000000000002").setScale(4, BigDecimal.ROUND_HALF_UP));


    }

    public static void json() {


        Foo foo = new Foo();
        foo.setF0(new BigDecimal(1.0123456789));
        foo.setF1("foo");
        String text = JSON.toJSONString(foo);
        System.out.println(text);


    }

    static class Foo {
        private BigDecimal f0;
        private String f1;

        public BigDecimal getF0() {
            return f0;
        }

        public void setF0(BigDecimal f0) {
            this.f0 = f0;
        }

        public String getF1() {
            return f1;
        }

        public void setF1(String f1) {
            this.f1 = f1;
        }
    }

}